<?php
include("include/bittorrent.php");
header("Content-Type: text/html; charset=".$tracker_lang['language_charset']);

cache_unset('ajax_actions');
/* My Ajax Module */
if ( ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') && !empty($_REQUEST['action']) && strlen($_REQUEST['action']<=10) ) {
	$action=$_REQUEST['action'];
	if ( !cache_check('ajax_actions') ) {
		$r=sql_query('SELECT `action`,`handler`,`file` FROM `ajax`');
		while(is_array(($data=mysql_fetch_array($r))) ) {
			$actions[$data['action']]['handler']=$data['handler'];
			$actions[$data['action']]['file']=$data['file'];			
		}
		cache_write('ajax_actions',$actions,10000);
	} else $actions=cache_read($ajax_actions);
	if ( is_array($actions[$action]) ) {
		$func=$actions[$action]['handler'];
		$file=$actions[$action]['file'];
		if ( file_exists('ajax/'.$file.'.inc') ) include('ajax/'.$file.'.inc');
		if ( is_callable($func) ) {
			call_user_func($func,$_REQUEST);
		} else {
			sql_query('DELETE FROM `ajax` WHERE `action` = '.$action);
			cache_unset('ajax_actions');
		}
	}
}
die();
?>